package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.TeachingLog;
import com.hwadee.teachingprocessmanagementsystem.dao.TeachingLogDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.TeachingLogService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 教学日志表(TeachingLog)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@Service("teachingLogService")
public class TeachingLogServiceImpl implements TeachingLogService {
    @Resource
    private TeachingLogDao teachingLogDao;

    /**
     * 通过ID查询单条数据
     *
     * @param logId 主键
     * @return 实例对象
     */
    @Override
    public TeachingLog queryById(Integer logId) {
        return this.teachingLogDao.queryById(logId);
    }

    /**
     * 分页查询
     *
     * @param teachingLog 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TeachingLog> queryByPage(TeachingLog teachingLog, PageRequest pageRequest) {
        long total = this.teachingLogDao.count(teachingLog);
        return new PageImpl<>(this.teachingLogDao.queryAllByLimit(teachingLog, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param teachingLog 实例对象
     * @return 实例对象
     */
    @Override
    public TeachingLog insert(TeachingLog teachingLog) {
        this.teachingLogDao.insert(teachingLog);
        return teachingLog;
    }

    /**
     * 修改数据
     *
     * @param teachingLog 实例对象
     * @return 实例对象
     */
    @Override
    public TeachingLog update(TeachingLog teachingLog) {
        this.teachingLogDao.update(teachingLog);
        return this.queryById(teachingLog.getLogId());
    }

    /**
     * 通过主键删除数据
     *
     * @param logId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer logId) {
        return this.teachingLogDao.deleteById(logId) > 0;
    }
}
